import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Index from "@/views/Index.vue";

import Error from "@/views/Error.vue";
import Login from "@/views/Login.vue";

Vue.use(VueRouter)

const routes = [
    {
      path: '/',
      name: 'login',
      component: Login
    },
    {
      path: '/error',
      name: 'error',
      component: Error
    },
  {
    path: '/index',
    name: 'index',
    component: Index
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to, from, next) => {
//      if(to.path.startsWith('/')){
//            //清除之前保存的用户的信息
//           if(window.sessionStorage.getItem("user")!=null) {
//               sessionStorage.removeItem('user');
//           }
//           next();
//      }else{
//          //获取保存的用户信息
//          let user  = JSON.parse( window.sessionStorage.getItem('user'));
//          //进行后端的验证
//          this.getRequest('checkToken',{params:{token: user.token}}).then(resp =>{
//               if(resp.data.flag){
//                    next();
//               }else{
//                   this.$message.error("token失效");
//                   next({path:'/error'})
//               }
//          })
//      }
// })

export default router
